<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="130" />
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="tableList"
      :isSelectColumn="false"
      height="auto"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" slot-scope="props">
      </template>
    </FilterTable>
     <BreakSpace label='操作记录' />
    <FilterTable
      ref="tables"
      :columns="columns1"
      :dataSource="tableLists"
      :datakey="'records'"
      :isSelectColumn="false"
      height='auto'
      :onColumnsChange="columns => this.columns1 = columns"
    >

    </FilterTable>

    <BaseDialog
      :visible.sync="isDiscount"
      :title="'折扣详情'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <DiscountDetail :rowData="DiscountData" @close="Discountclose" />
    </BaseDialog>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >


      <multiuse-button type="primary" :click="adopt" :disabled="this.rowData.status !=60631001">审核通过</multiuse-button>
      <multiuse-button type="primary" :click="back"  :disabled="this.rowData.status !=60631001">审核驳回</multiuse-button>
      <el-button @click="closeDrawer(1)">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import {getNotPage,getDetail,auditOne} from '@/api/omSale/OrderManagement/DirectSaleAudit/index.js'
import { dictionary } from '@/utils/dictMixin';
import Cookies from 'js-cookie'
import moment from 'moment';
export default {
  data(){
    this.saveData=null;
    return{
      formList:this.createdFrom(),
      columns:this.createdTable(),
      tableList:[],
      isaddCar:false,
      carData:{},
      json:{},
      isDiscount:false,
      DiscountData:{},
      TotalAmount:'',
      singleRebateAmount:'',
      buildRebateAmount:'',
      dealerCode:'',
      columns1:this.createdTables(),
      tableLists:[],
    }
  },
  components: {
  },
  props:['rowData'],
  created(){
    this.getDetail(this.rowData.id)
  },
  mounted() {
    this.table = this.$refs.table.$refs.pageTable;
  },
  mixins:[dictionary],
  methods:{
    createdFrom(){
      return [
        {
          type: 'BREAK_SPACE',
          label: '订单信息',

        },

        {
          type: 'INPUT',
          label: 'APP订单号',
          fieldName: 'appOrderNo',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'DATE',
          label: '订单年月',
          fieldName: 'orderYearMonth',
          disabled:true,
          placeholder: '请输入',
          dateType:'month',
          initialValue:moment().format('YYYY-MM')
        },
        {
          type: 'SELECT',
          label: '单据状态',
          fieldName: 'status',
          placeholder: '请选择',
          disabled:true,
          itemList: this.createDictList('6063')
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请选择',
          disabled:true,
          offsetRightCols: 1,
        },
        {
          type: 'INPUT',
          label: '客户姓名',
          fieldName: 'customerName',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '组织机构代码/身份证号',
          fieldName: 'customerCardNo',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '联系电话',
          fieldName: 'linkMobile',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '邮政编码',
          fieldName: 'postCode',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '联系地址',
          fieldName: 'linkAddress',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'SELECT',
          label: '开票类型',
          fieldName: 'billType',
          placeholder: '请选择',
          disabled:true,
          itemList: [
            {text:'专票',value: "0"},
            {text:'普票',value: "2"},
            {text:'机动车发票',value: "12"}
          ],
        },
        {
          type: 'INPUT',
          label: '基本价（销售指导价）',
          fieldName: 'basePrice',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '中央补贴',
          fieldName: 'nationalSubsidy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '地方补贴',
          fieldName: 'citySubsidy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '客户政策',
          fieldName: 'customerPolicy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '促定政策',
          fieldName: 'promotePolicy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '置换政策',
          fieldName: 'substitutePolicy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '单车政策',
          fieldName: 'singlePolicy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: 'VIP政策',
          fieldName: 'vipPolicy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '员工政策',
          fieldName: 'staffPolicy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '城市政策',
          fieldName: 'cityPolicy',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'INPUT',
          label: '其他政策',
          fieldName: 'otherPolicy',
          placeholder: '请选择',
          disabled:true,
          offsetRightCols: 1,
        },
        {
          type: 'INPUT',
          label: '授信单号',
          fieldName: 'creditNo',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'SELECT',
          label: '授信类型',
          fieldName: 'creditType',
          placeholder: '请选择',
          disabled:true,
          itemList: [
            {text:'循环授信',value: 1},
            {text:'单次授信',value: 2}
          ],
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请选择',
          disabled:true
        },
        {
          type: 'TEXT_AREA',
          label: '订单备注',
          fieldName: 'orderRemark',
          selfCols: 3,
          rows: 2,
          disabled: true,
        },
        {
          type: 'TEXT_AREA',
          label: '审核备注',
          fieldName: 'checkRemark',
          selfCols: 3,
          rows: 2,
        },
        {
          type: 'BREAK_SPACE',
          label: '价格折扣信息',

        },
      ]
    },
    createdTable(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '折扣名称',
          dataIndex: 'discountName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '折扣类型',
          dataIndex: 'discountType',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '折扣金额',
          dataIndex: 'amount',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input',
        }
      ]
    },
    createdTables(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '单据执行前状态',
          dataIndex: 'oldStatusStr',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '单独执行后状态',
          dataIndex: 'newStatusStr',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '操作人员',
          dataIndex: 'checkBy',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '操作时间',
          dataIndex: 'checkAt',
          sorter: true,
          filter: true,
          filterType: 'date-range',
        },
        {
          title: '审批意见',
          dataIndex: 'checkRemark',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ]
    },
    changeHandle(val){
      this.saveData=val;
    },
    async closeDrawer(type){
      if(type==1){
        this.$emit('close',type)
      }
    },
    Discountclose(){
      this.isDiscount=false;
    },
    async adopt(){
      this.$refs.from.SUBMIT_FORM();
      let res=await auditOne({id:this.rowData.id , status : 60631004,checkRemark:this.saveData.checkRemark})
      if (res.resultCode == 200) {
        this.$notify({
          title: '成功',
          message: '审核成功',
          type: 'success'
        });
        this.$emit('close');
      }else{

      }
    },
    async back(){
      this.$refs.from.SUBMIT_FORM();
      console.log("!!!!!!",this.saveData)
      if(this.saveData.checkRemark){
        let res=await auditOne({id:this.rowData.id , status : 60631003,checkRemark:this.saveData.checkRemark})
        if (res.resultCode == 200) {
          this.$notify({
            title: '成功',
            message: '审核成功',
            type: 'success'
          });
          this.$emit('close');
        }else{

        }
      }else {
        this.$notify.warning({title: '提示信息', message: '驳回时请维护审核备注！'});
      }

    },
    // 获取详情
    async getDetail(id){
      let res=await getDetail({id:id})
      for (let i in res.data) {
        this.formList.map((y) => {
          if (i == y.fieldName) {
            y.initialValue = res.data[i];
          }
        });
      }
      this.tableList = res.data.discountList || [];
      this.tableLists = res.data.auditList || [];
    },
  }
}
</script>
<style lang="less">
.discount{
  text-decoration:underline;
  color:#d1291a;
  cursor:pointer;
}
</style>
